﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using System.Configuration;
using System.Security.AccessControl;

namespace Incendios0_1.Camera.hplayer
{
    /// <summary>
    /// Interaction logic for WindowPlayer.xaml
    /// </summary>
    public partial class WindowPlayer : Window
    {
        public WindowPlayer()
        {
            InitializeComponent();
            List<string> lista = new List<string>();
            DirectoryInfo info;
            if (ConfigurationManager.AppSettings["VideoDirectory"] == string.Empty)
                info = new DirectoryInfo(Directory.GetCurrentDirectory());
            else
                info = new DirectoryInfo(ConfigurationManager.AppSettings["VideoDirectory"]);
            foreach (FileInfo f in info.GetFiles("*.asf",SearchOption.TopDirectoryOnly))
            {
                if (f.Extension == ".asf")
                {
                    try
                    {
                        f.OpenRead();
                        lista.Add(f.Name);
                    }
                    catch (System.IO.IOException) { }
                }
            }
            mediaList.ItemsSource = lista;
        }

        private void mediaList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MediaControl media = windowsFormsHost1.Child as MediaControl;
            AxWMPLib.AxWindowsMediaPlayer ply = media.axWindowsMediaPlayer1;
            if (ConfigurationManager.AppSettings["VideoDirectory"] == string.Empty)
                ply.URL = Directory.GetCurrentDirectory() + "\\" + mediaList.SelectedItem.ToString();
            else
                ply.URL = ConfigurationManager.AppSettings["VideoDirectory"] + "\\" + mediaList.SelectedItem.ToString();
            
        }


    }
}
